package com.cyp.blogsystem.service.impl;

import com.cyp.blogsystem.mapper.CategoryMapper;
import com.cyp.blogsystem.model.vo.CategoryVO;
import com.cyp.blogsystem.pojo.Category;
import com.cyp.blogsystem.service.CategoryService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor;
import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class CategoryServiceImpl implements CategoryService {

  private final CategoryMapper categoryMapper;

  @Override
  public List<CategoryVO> getCategoryList() {
    // 1. 查询所有分类
    List<Category> categories = categoryMapper.selectAll();

    // 2. 转换为VO对象
    return categories.stream()
            .map(this::convertToVO)
            .collect(Collectors.toList());
  }

  private CategoryVO convertToVO(Category category) {
    CategoryVO vo = new CategoryVO();
    BeanUtils.copyProperties(category, vo);
    return vo;
  }
}